!{include file='common/iheader.htm'}
<style>
.new_ns{display:none;}
.form_item .text_input{height:20px;line-height:20px;}
#cur_acl_list{display:none;}
.acl_item span{color:#158144;display:inline-block;}
.form_item textarea{width:400px;}
</style>
<div id="i_nav">
	<h3 class="page_title">权限编辑 </h3>
	<a class="button ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" href="/admin.php?app=acl"><span class="ui-icon ui-icon-document"></span>权限列表</a>
</div>
<form id="acl_edit_form" method="post" action="/admin.php" class="edit_form">
	<div class="form_item">
		<strong>　　命名空间：</strong>
		<div>
			<select name='namespace'>
				<option value='0'>新建模块</option>
				!{html_options options=$namespaces selected=$acl.namespace|default:0}
			</select>
		</div>
		<p></p>
	</div>
	<div id="cur_acl_list" class="form_item">
		<strong>　　现有权限：</strong>
		!{foreach from=$acl_list item=ns_info key=ns}
		<div class="acl_item ns_!{$ns}">
			!{foreach from=$ns_info.items item=c_acl key=a}
			!{if $c_acl}
			<span>
				!{$c_acl.name}[!{$a}]
			</span>
			!{/if}
			!{/foreach}
		</div>
		!{/foreach}
	</div>
	<div class="form_item new_ns">
		<strong>命名空间代码：</strong>
		<div><input class="text_input" type="text" name="new_ns"/></div>
		<p>请使用小写字母，长度不能超过8</p>
	</div>
	<div class="form_item new_ns">
		<strong>命名空间名称：</strong>
		<div><input class="text_input" type="text" name="new_desc"/></div>
		<p>不要与现有名称相同，以区分之</p>
	</div>
	<div class="form_item">
		<strong>　　权限名称：</strong>
		<div><input class="text_input" type="text" name="name" value="!{$acl.acl_name|default:''}"/></div>
		<p>可以使用中文</p>
	</div>
	<div class="form_item">
		<strong>　　　权限值：</strong>
		<div><input class="text_input" type="text" name="acl" value="!{$acl.acl_value|default:''}"/></div>
		<p>数值，同一“命名空间”下值不能重复</p>
	</div>
	<div class="form_item">
		<strong>　　权限描述：</strong>
		<div><textarea name="desc">!{$acl.acl_desc|default:''}</textarea></div>
	</div>
	<div class="form_item form_btn_item">
		<input class="button ui-button ui-widget ui-state-default ui-corner-all" type="button" id="acl_form_submit_btn" value="提交">
		<input type="hidden" name="app" value="acl"/>
		<input type="hidden" name="act" value="edit"/>
	</div>
	<div class="info ui-state-highlight ui-corner-all">正在提交，请稍候...</div>
</form>
<script>
	var busy = false;
	var options = {
		dataType : 'json',
		type : 'POST',
		success : function(data){
			busy = false;
			if(data.result){
				//成功
				alert(data.info);
				window.location.href='/admin.php?app=acl';//刷新界面
			}else{
				//失败
				$('#acl_edit_form .info').html(data.info).show();
			}
		}
	};
	
	$(function(){
		$('#acl_edit_form').ajaxForm(options);

		//提交保存
		$('#acl_form_submit_btn').click(function(){
			if(busy)return;
			busy = true;
			$('#acl_edit_form .info').html('正在提交，请稍候...').show();
			$('#acl_edit_form').submit();
		});
		$("select[name='namespace'] option").click(select_acl);
		$("select[name='namespace'] option:selected").click();
	});

	function select_acl(){
		var namespace = $("select[name='namespace'] option:selected").val();
		if(namespace=='0'){
			$(".new_ns").slideDown();
			$("#cur_acl_list").slideUp();
		}else{
			$("#cur_acl_list .acl_item").hide();
			$("#cur_acl_list .ns_" + namespace).show();
			$("#cur_acl_list").slideDown();
			$(".new_ns").slideUp();
		}
	}
</script>
!{include file='common/ifooter.htm'}